from django.shortcuts import render
from rest_framework.viewsets import ModelViewSet
from .models import *
from .serializer import *
from rest_framework.views import APIView
from rest_framework.generics import ListAPIView
from rest_framework.pagination import PageNumberPagination
# Create your views here.


# 定义分页的类
class MyPagination(PageNumberPagination):
    page_size = 3
    max_page_size = 5
    page_query_param = "page"
    page_size_query_param = "pagesize"


# 优惠券的视图集
class CouponViewSet(ModelViewSet):
    queryset = Coupon.objects.all()
    serializer_class = CouponSer
    lookup_field = "pk"
    lookup_url_kwarg = "pk"
    pagination_class = MyPagination


# 加载所有的优惠券类型
class CouponTypeAPIView(ListAPIView):
    queryset = CouponType.objects.all()
    serializer_class = CouponTypeSer














